package com.masterclient.app.modules.aftersale.adapter;

import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.bean.aftersale.ExpressBean;
import com.masterclient.app.R;

/**
 * 作者：sean
 * 创建时间：2017/8/4 17:24
 * 功能说明：
 */
public class SendLogisticAdapter extends BaseQuickAdapter<ExpressBean, BaseViewHolder> {

    private OnClickItemListener onClickItemListener;
    private boolean canUpdate;

    public SendLogisticAdapter(OnClickItemListener listener) {
        super(R.layout.item_send_logistic);
        this.onClickItemListener = listener;
    }

    public void setCanUpdate(boolean canUpdate) {
        this.canUpdate = canUpdate;
    }

    @Override
    protected void convert(BaseViewHolder helper, ExpressBean item) {
        View viewItem = helper.getView(R.id.view_item);
        TextView tvOrderStatus = helper.getView(R.id.tv_order_status);
        TextView tvExpressInfo = helper.getView(R.id.tv_express_info);
        TextView tvTransportInfo = helper.getView(R.id.tv_transport_info);
//        TextView tvTitle = helper.getView(R.id.tv_title);
//        TextView tvSku = helper.getView(R.id.tv_skus);
//        PriceIntegralLayout llPrice = helper.getView(R.id.ll_price);
//        TextView tvNum = helper.getView(R.id.tv_num);
//        ImageView ivGood = helper.getView(R.id.iv_good);

        if ("4".equals(item.trackStatus)){
            //已签收
            tvOrderStatus.setTextColor(Color.parseColor("#24B36B"));
        }else {
            //其他状态
            tvOrderStatus.setTextColor(Color.parseColor("#F23051"));
        }
        tvOrderStatus.setText(item.trackStatusDesc);
        tvExpressInfo.setText(String.format("%s %s", item.shipmentCompany, item.trackNo));
        tvTransportInfo.setText(item.latestTrackData);

//        tvTitle.setText(item.product.name);
//        tvNum.setText(item.product.qtyOrdered);
//        tvSku.setText(item.product.aliasName);
//        llPrice.setData("", item.product.price);
//        ViewTransformUtil.glideImageView(mContext, item.product.image, ivGood,
//                new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0),
//                R.mipmap.defaults, ScreenUtils.dp2px(100), ScreenUtils.dp2px(100));

        viewItem.setOnClickListener(v -> onClickItemListener.clickItem(item.trackNo));

        TextView tv = helper.getView(R.id.tv_express_update);
        tv.setVisibility(canUpdate?View.VISIBLE:View.GONE);
        tv.setOnClickListener(v -> onClickItemListener.clickUpdate(helper.getAdapterPosition()));
    }

    public interface OnClickItemListener{
        void clickItem(String id);
        void clickUpdate(int position);
    }
}
